import {
	mapState
} from 'vuex';
import {
	toNumber
} from '@/utils/transform';
	import {
		wxConfig
	} from '@/mixins/wxConfig';
export const confirm = {
	mixins: [wxConfig],
	data() {
		return {
			productIds: '',
			dataList: [],
			prodType: '', // 秒杀普通产品:seckill
			dataForm: {
				type: 1, // 1：默认，2:从购物车进来的
				pay_type:1,
			},
			dataArr: [],
			couponPrice: 0,
			selectList: [],
			allProdPrice: 0, // 产品总金额
			prodPostage: 0, // 运费邮费
			prodCount: 0, // 产品总数量
		}
	},
	computed: {
		...mapState(['vuex_address']),
		totalPrice() {
			if (this.checkPick) {
				return 0
			} else {
				return this.dataArr.reduce((pre, el) => {
					return pre += ( Number(el.amount) * Number(el.Pronum))
				}, 0)
			}
		}
	},

	onLoad(options) {
		let params = JSON.parse(options.params)
		this.dataArr = params.rowArray
		this.codeList = params.codeList
		this.initPage();
	},
	methods: {
		//初始化页面
		initPage() {
			let price = 0;
			let freight = 0;

			if (!this.dataArr[0]) return
			// #ifdef H5
			// h5需要先获取支付和地址的配置
			this.$loading();
			this.initWxConfig(['chooseWXPay', 'openAddress'])
				.then(() => {
					this.$hide()
				})
				.catch(() => this.$hide());
			// #endif

			this.dataArr.forEach(el => {
				this.selectList.push({
					product_img: el.img,
					product_name: el.pro_name,
					price: el.price,
					num:el.Pronum
				})
				price += (Number(el.price)  * Number(el.Pronum))
				freight += (Number(el.amount) * Number(el.Pronum))
			})
			this.orederCell = {
				price,
				freight
			}

			let fk_prodtct_id_list = this.dataArr.reduce((pre, el) => {
				pre.push(el.fk_prodtct_id)
				return pre
			}, [])
			this.$refs.pick_up_view.getPickupList(fk_prodtct_id_list)

		},

	}
}
